package day08.synch;

/**
 * @Auther: sky
 * @Date: 2019/3/4 22:37
 * @Description:同步
 */
public class SyncTest {

    private  int num=0;
    synchronized public void add(String userName){

       try{
           if(userName.equals("a")){
               System.out.println("a over");
               Thread.sleep(2000);
               num=100;
           }else {
               num=200;
               System.out.println("b over");
           }
           System.out.println(userName+",num="+num);
       }catch (Exception e){
           e.printStackTrace();
       }

    }


}
